<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Send an SQL query to Ingres</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ingres-prepare.html">ingres_prepare</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ingres-result-seek.html">ingres_result_seek</a></div>
 <div class="up"><a href="ref.ingres.html">Ingres 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.ingres-query" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ingres_query</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5 &lt;= 5.0.5, PECL ingres &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">ingres_query</span> &mdash; <span class="dc-title">Send an SQL query to Ingres</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ingres-query-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>ingres_query</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$params</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$types</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>ingres_query()</strong></span> sends the given
   <em><code class="parameter">query</code></em> to the Ingres server. 
  </p>
  <p class="para">
   The query becomes part of the currently open transaction.  If
   there is no open transaction, <span class="function"><strong>ingres_query()</strong></span>
   opens a new transaction. To close the transaction, you can 
   call either <span class="function"><a href="function.ingres-commit.html" class="function">ingres_commit()</a></span> to commit the changes
   made to the database or <span class="function"><a href="function.ingres-rollback.html" class="function">ingres_rollback()</a></span> to
   cancel these changes. When the script ends, any open transaction
   is rolled back (by calling
   <span class="function"><a href="function.ingres-rollback.html" class="function">ingres_rollback()</a></span>). You can also use
   <span class="function"><a href="function.ingres-autocommit.html" class="function">ingres_autocommit()</a></span> before opening a new
   transaction to have every SQL query immediately committed.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>Related Configurations</strong><br />
   <p class="para">
    See also the <a href="ingres.configuration.html#ini.ingres.describe" class="link">ingres.describe</a>,
    <a href="ingres.configuration.html#ini.ingres.scrollable" class="link">ingres.scrollable</a> and
    <a href="ingres.configuration.html#ini.ingres.utf8" class="link">ingres.utf8</a> directives in 
    <a href="ingres.configuration.html" class="link">Runtime Configuration</a>
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ingres-query-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">link</code></em></dt>

     <dd>

      <p class="para">
       The connection link identifier.
      </p>
     </dd>

    
    
     <dt id="function.ingres-query.query"><em><code class="parameter">query</code></em></dt>

     <dd>

      <p class="para">
       A valid SQL query (see the Ingres <em>SQL reference
       guide</em>) in the Ingres documentation.
      </p>
      <p class="para">
       Data inside the query should be <a href="function.ingres-escape-string.html" class="link">properly escaped</a>.
      </p>
      <p class="para">
       The following types of SQL queries cannot be sent with this function:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <em>close</em> (see <span class="function"><a href="function.ingres-close.html" class="function">ingres_close()</a></span>)
         </span>
        </li>
       <li class="listitem">
         <span class="simpara">
          <em>commit</em> (see <span class="function"><a href="function.ingres-commit.html" class="function">ingres_commit()</a></span>)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <em>connect</em> (see <span class="function"><a href="function.ingres-connect.html" class="function">ingres_connect()</a></span>)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <em>disconnect</em> (see <span class="function"><a href="function.ingres-close.html" class="function">ingres_close()</a></span>)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara"><em>get dbevent</em></span>
        </li>
        <li class="listitem">
         <span class="simpara"><em>prepare to commit</em></span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <em>rollback</em> (see <span class="function"><a href="function.ingres-rollback.html" class="function">ingres_rollback()</a></span>)
         </span>
        </li>
        <li class="listitem"><span class="simpara"><em>savepoint</em></span></li>
        <li class="listitem">
         <span class="simpara">
          <em>set autocommit</em> (see <span class="function"><a href="function.ingres-autocommit.html" class="function">ingres_autocommit()</a></span>)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">all cursor-related queries are unsupported</span>
        </li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">params</code></em></dt>

     <dd>

      <p class="para">
       An array of parameter values to be used with the query
      </p>
     </dd>

    
    
     <dt id="function.ingres-query.types"><em><code class="parameter">types</code></em></dt>

     <dd>

      <p class="para">
       A string containing a sequence of types for the parameter values
       passed. When <a href="ingres.configuration.html#ini.ingres.describe" class="link">ingres.describe</a>
       is enabled, this parameter can be ignored as the driver automatically
       fetches the expected parameter types from the server.
      </p>
      <table class="doctable informaltable">
       
        <thead>
         <tr>
          <th>Type code</th>
          <th>Ingres type</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>a</td>
          <td><span class="type"><a href="language.types.boolean.html" class="type BOOLEAN">BOOLEAN</a></span></td>
         </tr>

         <tr>
          <td>b</td>
          <td><span class="type"><span class="type BYTE">BYTE</span></span></td>
         </tr>

         <tr>
          <td>B</td>
          <td><span class="type"><span class="type LONG BYTE/BLOB">LONG BYTE/BLOB</span></span></td>
         </tr>

         <tr>
          <td>c</td>
          <td><span class="type"><span class="type CHAR">CHAR</span></span></td>
         </tr>

         <tr>
          <td>d</td>
          <td><span class="type"><span class="type DATE/ANSIDATE/TIMESTAMP/TIME">DATE/ANSIDATE/TIMESTAMP/TIME</span></span></td>
         </tr>

         <tr>
          <td>f</td>
          <td><span class="type"><a href="language.types.float.html" class="type FLOAT">FLOAT</a></span></td>
         </tr>

         <tr>
          <td>i</td>
          <td><span class="type"><a href="language.types.integer.html" class="type INTEGER">INTEGER</a></span></td>
         </tr>

         <tr>
          <td>L</td>
          <td><span class="type"><span class="type LONG TEXT">LONG TEXT</span></span></td>
         </tr>

         <tr>
          <td>m</td>
          <td><span class="type"><span class="type MONEY">MONEY</span></span></td>
         </tr>

         <tr>
          <td>M</td>
          <td><span class="type"><span class="type LONG NVARCHAR">LONG NVARCHAR</span></span></td>
         </tr>

         <tr>
          <td>n</td>
          <td><span class="type"><span class="type NCHAR">NCHAR</span></span></td>
         </tr>

         <tr>
          <td>N</td>
          <td><span class="type"><span class="type NVARCHAR">NVARCHAR</span></span></td>
         </tr>

         <tr>
          <td>t</td>
          <td><span class="type"><span class="type TEXT">TEXT</span></span></td>
         </tr>

         <tr>
          <td>v</td>
          <td><span class="type"><span class="type VARCHAR">VARCHAR</span></span></td>
         </tr>

         <tr>
          <td>V</td>
          <td><span class="type"><span class="type LONG VARCHAR">LONG VARCHAR</span></span></td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ingres-query-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>ingres_query()</strong></span> returns a query result identifier on
   success else it returns <strong><code>FALSE</code></strong>. To see if an error
   occurred use <span class="function"><a href="function.ingres-errno.html" class="function">ingres_errno()</a></span>, 
   <span class="function"><a href="function.ingres-error.html" class="function">ingres_error()</a></span> or 
   <span class="function"><a href="function.ingres-errsqlstate.html" class="function">ingres_errsqlstate()</a></span>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ingres-query-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1194">
    <p><strong>Example #1 Send a simple select</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;user_profile"</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-1195">
    <p><strong>Example #2 Passing query parameters to <span class="function"><strong>ingres_query()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$params</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"Emma"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;user_profile&nbsp;where&nbsp;up_first&nbsp;=&nbsp;?"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-1196">
    <p><strong>Example #3 Inserting a BLOB with parameter types</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//Open&nbsp;a&nbsp;photo<br /></span><span style="color: #0000BB">$fh&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"photo.jpg"</span><span style="color: #007700">,</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$blob_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$fh</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//Prepare&nbsp;parameters<br /></span><span style="color: #0000BB">$params</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$blob_data</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$params</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">1201</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//Define&nbsp;parameter&nbsp;types<br /></span><span style="color: #0000BB">$param_types&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Bi"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"update&nbsp;user_profile&nbsp;set&nbsp;up_image&nbsp;=&nbsp;?&nbsp;where&nbsp;up_id&nbsp;=&nbsp;?"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ingres_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param_types</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">ingres_errno</span><span style="color: #007700">())<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">ingres_errno</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"-"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">ingres_error</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">ingres_commit</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">ingres_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ingres-query-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ingres-unbuffered-query.html" class="function" rel="rdfs-seeAlso">ingres_unbuffered_query()</a> - Send an unbuffered  SQL query to Ingres</span></li>
    <li class="member"><span class="function"><a href="function.ingres-fetch-array.html" class="function" rel="rdfs-seeAlso">ingres_fetch_array()</a> - Fetch a row of result into an array</span></li>
    <li class="member"><span class="function"><a href="function.ingres-fetch-assoc.html" class="function" rel="rdfs-seeAlso">ingres_fetch_assoc()</a> - Fetch a row of result into an associative array</span></li>
    <li class="member"><span class="function"><a href="function.ingres-fetch-object.html" class="function" rel="rdfs-seeAlso">ingres_fetch_object()</a> - Fetch a row of result into an object</span></li>
    <li class="member"><span class="function"><a href="function.ingres-fetch-row.html" class="function" rel="rdfs-seeAlso">ingres_fetch_row()</a> - Fetch a row of result into an enumerated array</span></li>
    <li class="member"><span class="function"><a href="function.ingres-commit.html" class="function" rel="rdfs-seeAlso">ingres_commit()</a> - Commit a transaction</span></li>
    <li class="member"><span class="function"><a href="function.ingres-rollback.html" class="function" rel="rdfs-seeAlso">ingres_rollback()</a> - Roll back a transaction</span></li>
    <li class="member"><span class="function"><a href="function.ingres-autocommit.html" class="function" rel="rdfs-seeAlso">ingres_autocommit()</a> - Switch autocommit on or off</span></li>
    <li class="member"><span class="function"><a href="function.ingres-set-environment.html" class="function" rel="rdfs-seeAlso">ingres_set_environment()</a> - Set environment features controlling output options</span></li>
    <li class="member"><span class="function"><a href="function.ingres-errno.html" class="function" rel="rdfs-seeAlso">ingres_errno()</a> - Get the last Ingres error number generated</span></li>
    <li class="member"><span class="function"><a href="function.ingres-error.html" class="function" rel="rdfs-seeAlso">ingres_error()</a> - Get a meaningful error message for the last error generated</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ingres-prepare.html">ingres_prepare</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ingres-result-seek.html">ingres_result_seek</a></div>
 <div class="up"><a href="ref.ingres.html">Ingres 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
